package com.wwj.pedigreecertificationsystem;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;

/**
 * @author wwj
 * @version 1.0
 * @date 2022/03/30 14:51
 */
@Controller
public class AuthController {

    @GetMapping("/")
    public String toIndex() {
        return "index";
    }

    // https://www.chsi.com.cn/xlcx/bg.do?vcode=AM5W7Q5G68MUFDF1&srcid=bgcx
    @GetMapping("/auth")
    public String auth(@RequestParam("code") String code, Map<String, String> map) throws Exception {
        // 调用Python完成认证
        String exe = "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python39\\python";
        String command = "C:\\Users\\Administrator\\Desktop\\demo\\main.py";
        String[] cmdArr = new String[]{exe, command, code};
        Process process = Runtime.getRuntime().exec(cmdArr);
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream(), "GB2312"));
        String s = in.readLine();
        process.waitFor();
        map.put("msg", s);
        return "result";
    }
}
